package com.twu.biblioteca.login;

import com.twu.biblioteca.library.Users;
import com.twu.biblioteca.streams.AppOutputStream;
import com.twu.biblioteca.streams.UserInputStream;

import java.io.IOException;

public class LoginInterceptor {

    public void login() throws IOException {
        while (LoginStatus.loggedInLibNumber == null) {
            AppOutputStream.writeLine("Please input your library number:\n");
            String libraryNumber = UserInputStream.readLine();

            AppOutputStream.writeLine("Please input your password:\n");
            String password = UserInputStream.readLine();

            boolean validateResult = new Users().validateUser(libraryNumber, password);
            if (validateResult) {
                LoginStatus.loggedInLibNumber = libraryNumber;
            }
        }
    }
}
